/* Evaluates electron number density n(0:J-1) 
   from array r(0:N-1) of electron coordinates */ 
#include "mine.h"

void Density (Array<double,1> r, Array<double,1>& ne)
{
    // Initialize
    double dx = L / double (J);
    ne = 0.0;
    
    // Evaluate number density
    for (int i = 0; i < N; i++) {
	int j = int (r(i) / dx); // In which cell
	double y = r(i) / dx - double (j); // The position in this cell
	ne(j) += (1.0 - y) / dx;
	if (j+1 == J) ne(0) += y / dx; // The periodic condition
	else ne(j+1) += y / dx;
    }
}
